# -*- coding: utf-8 -*-

import logging

import py_global

logger = logging.getLogger(__name__)


class SuperClass(object):
    """超类"""

    def __init__(self):
        self.filed = 'zxcv'
        pass

    def method(self):
        pass


class SubClass(SuperClass):
    """子类"""

    def __init__(self):
        super().__init__()
        self.tmp = 'qwer'

    def method(self):
        pass

    pass


class BaseClass(object):
    """基类"""

    @classmethod
    def class_method(cls):
        logger.info(f'class {cls.__name__} call')


def test_create_dynamic_type():
    """
    创建动态类型
    Returns
    -------

    """
    ClassType = type('ClassName', (BaseClass,), {})  # noqa
    ClassType.class_method()  # noqa


class ClassTop(object):

    def method(self):
        logger.info('ClassTop')


class ClassLeft(object):
    def method(self):
        logger.info('ClassLeft MRO:%s' % ClassLeft.mro())
        if hasattr(super(), 'method'):
            super().method()  # noqa

        logger.info('ClassLeft')


class ClassRight(ClassTop):
    def method(self):
        logger.info('ClassRight MRO:%s' % ClassRight.mro())

        logger.info('ClassRight')


class ClassBottom(ClassLeft, ClassRight):

    def __init__(self):
        # 子类构造函数中必须调用父类的构造函数
        # 注意继承多个类时出现同名方法，括号中前面的类回覆盖后面的类
        super(ClassLeft, self).__init__()
        super(ClassRight, self).__init__()

    def method(self):
        logger.info('ClassBottom MRO:%s' % ClassBottom.mro())

        # super(ClassLeft, self).method()
        # super(ClassRight, self).method()
        super().method()
        logger.info('ClassBottom')


def test_multiple_inheritance():
    """
    多继承：菱形继承（钻石继承）
    Returns
    -------

    """
    ClassBottom().method()
    ClassLeft().method()


if __name__ == '__main__':
    # test_create_dynamic_type()
    test_multiple_inheritance()
    pass
